package com.ssyt.yt1.day13;

import java.io.IOException;
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;
import java.util.regex.Pattern;

/**
 * 其它常用类
 * 
 * @author Administrator
 *
 */
public class OtherClassDemo {

	public static void main(String[] args) throws IOException,
			InterruptedException {
		// Math
		System.out.println(Math.random());
		System.out.println(Math.ceil(11.5));
		System.out.println(Math.floor(11.5));
		System.out.println(Math.round(11.5));
		System.out.println(Math.round(-11.5));

		// Random
		Random random = new Random();
		System.out.println(random.nextInt(5) + 1);
		System.out.println(random.nextBoolean());

		// System
		// System.exit(0);
		System.out.println();
		System.out.println(System.currentTimeMillis());
		System.out.println(System.nanoTime());
		int[] numbers1 = { 1, 2, 3 };
		int[] numbers2 = new int[numbers1.length + 1];
		System.arraycopy(numbers1, 0, numbers2, 0, numbers1.length);
		numbers2[numbers2.length - 1] = 4;
		System.out.println(Arrays.toString(numbers2));
		// Runs the garbage collector.（不推荐调用！）
		// System.gc(); 等同于Runtime.getRuntime().gc()

		long start = System.currentTimeMillis();
		String str = "";
		for (int i = 0; i < 10000; i++) {
			str += i;
		}
		System.out.println(System.currentTimeMillis() - start);

		long start2 = System.currentTimeMillis();
		StringBuilder str2 = new StringBuilder();
		for (int i = 0; i < 10000; i++) {
			str2.append(i);
		}
		System.out.println(System.currentTimeMillis() - start2);

		// Runtime
		// Process process = Runtime.getRuntime().exec("mspaint");
		// Thread.sleep(3000);
		// process.destroy();

		// Scanner
		System.out.println("请输入此刻的心里的阴影面积？");
		Scanner scanner = new Scanner(System.in);
		// System.out.println(scanner.next());
		System.out.println(scanner.nextLine());
		// scanner.nextInt();

		// 正则表达式
		Pattern pattern = Pattern.compile("^\\w+@\\w+\\.\\w+$");
		boolean result = pattern.matcher("759694429@qq.com").matches();
		System.out.println(result);
	}
}
